import 'package:blog/app/package_info.dart';
import 'package:blog/base/get/controller/base_page_controller.dart';
import 'package:blog/model/lightcloud/condition_card.dart';
import 'package:blog/model/lightcloud/recommend_card.dart';
import 'package:blog/model/project_model.dart';
import 'package:blog/util/ext/refresher_extension.dart';
import 'package:blog/widget/pull_smart_refresher.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';


/// @class : ProjectController
/// @date : 2021/08/23
/// @name : CTGU_LLZ(404name)
/// @description :项目 控制器层
class ShopController extends BaseGetPageController {

  List<ProjectDetail> projectData = [];



  ///请求积分明细
  @override
  void requestData(RefreshController controller,
      {Refresh refresh = Refresh.first}) {
    request.requestGoodsCard(page, success: (data, over) {
      RefreshExtension.onSuccess(controller, refresh, over);

      ///下拉刷新需要清除列表
      if (refresh != Refresh.down) {
        projectData.clear();
      }
      data.forEach((element) {
        projectData.add(new ProjectDetail(
            apkLink: PackageInfo.webUrl + '/articles/' + element.id.toString(),
            audit: 0,
            author: element.categoryName,
            canEdit: false,
            chapterId: element.categoryId,
            chapterName: element.categoryName,
            collect: false,
            courseId: 0,
            desc: element.articleCover,
            descMd: element.articleCover,
            envelopePic: element.articleCover,
            fresh: false,
            host: "",
            id: element.id,
            link: PackageInfo.webUrl + '/articles/' + element.id.toString(),
            niceDate: element.createTime.replaceAll("T", " ").substring(0,19),
            niceShareDate: element.createTime.replaceAll("T", " ").substring(0,19),
            origin: PackageInfo.webUrl + '/articles/' + element.id.toString(),
            prefix: PackageInfo.webUrl + '/articles/' + element.id.toString(),
            projectLink: PackageInfo.webUrl + '/articles/' + element.id.toString(),
            publishTime: 0,
            realSuperChapterId: 0,
            selfVisible: 0,
            shareDate: 0,
            shareUser: "404name",
            superChapterId: 0,
            superChapterName: "0.0",
            tags: element.tagDTOList,
            title: element.articleTitle,
            type: element.categoryId,
            userId: 1,
            visible: 1,
            zan: int.parse(element.articleHeat)));
      });
      showSuccess(projectData);
      update();
    }, fail: (code, msg) {
      showError();
      RefreshExtension.onError(controller, refresh);
    });
  }
}
